package com.ruiysoft.service.integralmdse.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruiysoft.entity.integralmdse.MerchandiseSkuMPRela;
import com.ruiysoft.mapper.integralmdse.MerchandiseSkuMPRelaMapper;
import com.ruiysoft.service.integralmdse.IMerchandiseSkuMPRelaService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liyahui
 * @since 2019-04-27
 */
@Service
public class MerchandiseSkuMPRelaServiceImpl extends ServiceImpl<MerchandiseSkuMPRelaMapper, MerchandiseSkuMPRela> implements IMerchandiseSkuMPRelaService {

    @Override
    @Transactional
    public void save(List<MerchandiseSkuMPRela> merchandiseSkuMPRelas, List<Long> skuIds) {
//        List<Long> skuIds = merchandiseSkuMPRelas.stream().map(MerchandiseSkuMPRela::getSkuId).distinct().collect(Collectors.toList());
        if(skuIds==null||skuIds.isEmpty()){
            throw new RuntimeException("skuId不能为空");
        }
        remove(new QueryWrapper<MerchandiseSkuMPRela>() {
        }.in("sku_id",Objects.requireNonNull(skuIds,"skuId不能为空")));
        if(merchandiseSkuMPRelas!=null&&!merchandiseSkuMPRelas.isEmpty()){
            saveBatch(merchandiseSkuMPRelas);
        }
    }
}
